package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webservice.MarketPlaceProxy;


public class Payment extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public Payment() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String emailId = request.getSession().getAttribute("activeUser").toString();
		MarketPlaceProxy proxy = new MarketPlaceProxy();
		String result =  proxy.payment(emailId, 
						 request.getParameter("creditcardnum").toString(),
						 request.getParameter("cvvnum").toString());
		if (result.contains("ERR"))
		{
			request.setAttribute("Error", result);
			getServletContext().getRequestDispatcher("/sampleMarketPlaceProxy" +
		    "/WelcomeError.jsp").forward(request, response);
		}
		else
		{
			request.setAttribute("successstr", "Payment successfully done..");
			getServletContext().getRequestDispatcher("/sampleMarketPlaceProxy" +
		    "/WelcomePaymentSuccess.jsp").forward(request, response);
		}
	}
}
